package com.gitee.wsl.compose.mvi.component

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.gitee.wsl.compose.mvi.component.base.Interactable
import com.gitee.wsl.compose.mvi.component.base.Presentable

abstract class InteractionSourceSlotProjector<Interactor, Presenter,Scope>(
    override val interactor: Interactor,
    override val presenter: Presenter
) : Projectable<Interactor, Presenter> where Interactor : Interactable, Presenter : Presentable<Presenter> {

    @Composable
    abstract fun body(combinedModifier: Modifier, interactor:Interactor, presenter:Presenter, interactionSource: MutableInteractionSource, slot: @Composable Scope.() -> Unit)


    @Composable
    operator fun invoke(modifier: Modifier = Modifier,
                        interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
                         content: @Composable Scope.() -> Unit)
            = contextualize(modifier){ combinedModifier, interactor, presenter ->
        body(combinedModifier,interactor,presenter,interactionSource,content)
    }

    @Composable
    operator fun invoke(modifier: Modifier = Modifier,
                        interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
                        vararg content: @Composable Scope.() -> Unit)
            = contextualize(modifier){ combinedModifier, interactor, presenter ->
        body(combinedModifier,interactor,presenter,interactionSource){
            content.forEach {
                it()
            }
        }
    }
}